{% extends 'base.html' %}
{% import '_macros.html' as macros %}

{% block js %}
    <script>
        $(function () {
            $('.add-menu').click(function () {
                $('.modal-content').load('{{ url_for('menu.menu_create') }}');
                $('#myModal').modal('show')
            });

            $('.edit-menu').click(function () {
                var menu_id = $(this).attr('menu_id');
                $('.modal-content').load('/menu/edit/' + menu_id);
                $('#myModal').modal('show')
            });

            $('.delete-menu').click(function () {
                var menu_id = $(this).attr('menu_id');
                $('.modal-content').load('/menu/delete/' + menu_id);
                $('#myModal').modal('show')
            });
        });
    </script>
{% endblock %}

{% block right %}
    <div class="col-md-12 page-body">
        <div class="row">
            <div class="sub-title">
                <h2>菜单管理</h2>
                <a href="{{ url_for('main.index') }}" title="返回首页"><i class="icon-home"></i></a>
                <a href="#" title="新增菜单" class="add-menu"><i class="icon-plus"></i></a>
            </div>
            <div class="col-md-12 content-page">
                <table class="table table-hover list-table">
                    <tbody>
                    {% for menu in pagination.items %}
                        <tr>
                            <td>
                                <a href="#" >{{ menu.title[:20] }} #{{ menu.position }}</a>
                            </td>
                            <td>{{ menu.code }}</td>
                            <td>{{ menu.link_url[:20] }}</td>
                            <td>{% if menu.is_admin %}是{% else %}否{% endif %}</td>
                            <td>{{ menu.update_on }}</td>
                            {% if current_user.is_authenticated %}
                                <td>
                                    <a href="#" class="edit-menu" title="编辑" menu_id="{{ menu.id }}">
                                        <i class="icon-pencil"></i>
                                    </a>
                                    <a href="#" class="delete-menu" title="删除" menu_id="{{ menu.id }}">
                                        <i class="icon-trash"></i>
                                    </a>
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                <div class="my-pagination">
                    {{ macros.pagination_widget(pagination, 'menu.menu_list') }}
                </div>
            </div>
        </div>
    </div>
    {{ super() }}
{% endblock %}